package top.btcmarket.auth.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class EncryptUtil {

	//从配置文件中获得  
//	   private static final String SITE_WIDE_SECRET = "secret";  
//	   private static final PasswordEncoder encoder = new StandardPasswordEncoder(SITE_WIDE_SECRET);  
	   // hash 算法 每次都不一样
	   private static final PasswordEncoder encoder = new BCryptPasswordEncoder(); 
//	   private static final Md5PasswordEncoder encoder = new Md5PasswordEncoder();  
	   
	   
	  
	   public static String encrypt(String rawPassword) {  
	        return encoder.encode(rawPassword);  
//	        return encoder.encodePassword(rawPassword, null);
	   }  
	  
	   public static boolean match(String rawPassword, String password) {  
	        return encoder.matches(rawPassword, password);  
//		   return false ;
	   }  
	   
	   public static void main(String[] args) {
		   
		   System.out.println(encrypt("123456"));
		   String pwd22 = encrypt("123456");
		   String pwd = encrypt("123456") ;
		   System.out.println(pwd);
		   System.out.println(encoder.matches("123456",pwd22));
		   System.out.println(encoder.matches("123456",pwd));
		   System.out.println(encoder.matches("123456",encrypt("123456")));
//		   boolean flag = encoder.isPasswordValid("123456e10adc3949ba59abbe56e057f20f883e", "123456", null);
		   
//		   System.out.println(" flag ----"+flag);
	   }
}
